home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / misc / gencidrzone < prev    next >
Encoding:
Text File  |  1996-10-25  |  7.5 KB  |  284 lines

  1. #Date:    Wed, 26 Jun 1996 08:03:05 +0800
  2. #To:      paul@vix.com
  3. #cc:      andras@dns.net
  4. #From:    Mathias Koerber <mathias@venus-flytrap.singnet.com.sg>
  5. #Subject: new gencidrzone
  6. #
  7. #Paul. here is a new version of the gencidrzone script for your
  8. #next BIND distribution. I cleaned it up a lot, added support for
  9. #options to specify nameservers, SOA values to be put into the files etc.
  10. #You can now also use arbitrary names for your subdomain.
  11. #And it finally has a version number :-)
  12. #
  13. #rgds
  14. #
  15. #---cut here---
  16. #!/usr/bin/perl
  17. #
  18. #$Id: gencidrzone,v 8.1 1996/10/25 17:07:57 vixie Exp $
  19. #
  20. #    gencidrzone - generate zone and include files for 
  21. #            classless in-addr delegation
  22. #
  23. #    (C)Copyright 1996 Mathias Koerber <mathias@singnet.com.sg>
  24. #    Free to use for all
  25. #    No warranties, claims etc .. 
  26. #
  27. #    generates 2 files:
  28. #        1. skeleton/sample zonefile for subdomain.
  29. #        2. include file for parent zone. Include file
  30. #           contains: delegation NS records and all CNAME records
  31. #
  32. #    see usage below
  33. #
  34. #$Log: gencidrzone,v $
  35. #Revision 8.1  1996/10/25 17:07:57  vixie
  36. #BIND 4.9.5 T6B
  37. #
  38. #Revision 0.93  1996/06/25 23:56:04  mathias
  39. #cleaned up a bit more
  40. #
  41. #Revision 0.92  1996/06/25 23:46:31  mathias
  42. #more typos fixed :-(
  43. #
  44. #Revision 0.91  1996/06/25 23:44:47  mathias
  45. #minor typos
  46. #
  47. #Revision 0.9  1996/06/25 23:42:11  mathias
  48. #added optios
  49. #cleaned up generated files
  50. #now has better usage description
  51. #
  52. #
  53.  
  54. require "newgetopt.pl";
  55.  
  56. ($secs,$min,$hour,$mday,$mon,$year) = localtime();
  57. $opt_serial = sprintf("%-2.2d%-2.2d%-2.2d01",$year,($mon+1),$mday);
  58.  
  59. # some defaults
  60. $opt_primary        = "<your_primary>";
  61. $opt_contact        = "<zone_contact_address>";
  62. #@opt_secondary        = ("<your_secondary>");
  63. $opt_refresh        = 3600;
  64. $opt_retry        = 1200;
  65. $opt_expire        = 3600000;
  66. $opt_minimum        = 86400;
  67.  
  68. if ((NGetOpt(
  69.     "subdomain=s",
  70.     "primary=s",
  71.     "contact=s",
  72.     "secondary=s@",
  73.     "serial=s",
  74.     "refresh=i",
  75.     "retry=i",
  76.     "expire=i",
  77.     "minimum=i",
  78.     ) == 0) || ($#ARGV != 0)) {
  79.     print STDERR <<EOF;
  80. usage $0 [options] <addressblock> 
  81.  
  82. where:     <addressblock> is the block in prefix-length notation
  83. options include:
  84.     -subdomain <name>    name for the subdomain to 
  85.                 be delegated
  86.         default: last byte of the first address 
  87.             in the block (in decimal)
  88.         example: aaa.bbb.ccc.128/26
  89.             default:
  90.                 128.ccc.bbb.aaa.in-addr.arpa
  91.             -subdomain them:
  92.                 them.ccc.bbb.aaa.in-addr.arpa
  93.     -primary <name>        name of the primary server
  94.     -secondary <name>    secondary NS (may appear mult. times)
  95.     -contact <email_addr>    SOA contact address
  96.         defaults: placeholder strings for these..
  97.     -serial <number>    default SOA value
  98.     -refresh <number>        -"-
  99.     -retry <number>            -"-
  100.     -expire <number>        -"-
  101.     -minimum <number>        -"-
  102.         default: reasonable values for these..
  103. EOF
  104.     exit 2;
  105.     }
  106.  
  107. @opt_secondary = ("<your_secondary>") if (!@opt_secondary);
  108.  
  109. #perform some courtesy translations
  110. $opt_contact =~ tr/\@/./;
  111. # and some sanity ones
  112. chop($opt_primary) if ($opt_primary =~ /\.$/);
  113. chop($opt_contact) if ($opt_contact =~ /\.$/);
  114. for $i (0 .. $#opt_secondary) {
  115.     chop($opt_secondary[$i]) if ($opt_secondary[$i] =~ /\.$/);
  116.     }
  117.     
  118.  
  119. ($ip,$bits) = split('/',$ARGV[0]);
  120. ($a,$b,$c,$d) = split(/\./,$ip);
  121.  
  122. if ($bits <= 24) {
  123.     print "gencidrzone only makes sense for prefixes > 24bits.\n Pls try ag
  124. ain\n";
  125.     exit(2);
  126.     }
  127.  
  128. $add1 = (($a * (256**3)) + ($b * (256**2)) + ($c * (256**1)) + $d);
  129. $mb = (2**32)-(2**(32-$bits));
  130. $mb2 = 2**(32-$bits)-1;
  131.  
  132. $add2 = ($add1 & $mb);
  133. $add3 = ($add2 | $mb2);
  134.  
  135. ($fa,$fb,$fc,$fd) = &unp($add2);
  136. ($la,$lb,$lc,$ld) = &unp($add3);
  137.  
  138. $subdomain = $opt_subdomain ? $opt_subdomain : $fd;
  139.  
  140. open(SUB,">$subdomain.$fc.$fb.$fa.db");
  141. open(INC,">$fc.$b.$fa.inc.$subdomain");
  142.  
  143. print SUB <<"EOF";
  144. ;
  145. ;    CIDRD reverse delegation
  146. ;        for $ARGV[0]
  147. ;        (addresses from $fa.$fb.$fc.$fd to $la.$lb.$lc.$ld)
  148. ;
  149. ;    This is the reverse zone file for the sub-zone 
  150. ;        $subdomain.$fc.$fb.$fa.in-addr.arpa
  151. ;
  152. ;    Your site has been allocated the address range $ARGV[0]
  153. ;        (addresses from $fa.$fb.$fc.$fd to $la.$lb.$lc.$ld)
  154. ;
  155. ;    Since this range is smaller than a classical Class C (/24), 
  156. ;    you cannot be given authority over the full 
  157. ;        $fc.$fb.$fa.in-addr.arpa reverse domain
  158. ;    (you are sharing it with other networks).
  159. ;
  160. ;    For this reason we are only allocating you a subdomain of the 
  161. ;    above reverse domain. This subdomain is called 
  162. ;        $subdomain.$fc.$fb.$fa.in-addr.arpa.
  163. ;
  164. ;    To set up a primary nameserver for this (reverse) domain, you 
  165. ;    will need to add a line
  166. ;
  167. ;    ...
  168. ;    primary    $subdomain.$fc.$fb.$fa.in-addr.arpa <zonefile>
  169. ;    ...
  170. ;
  171. ;    into your nameserver's named.boot file, where <zonefile> will 
  172. ;    have to be replaced with the path/filename of your zonefile.
  173. ;
  174. ;    You may use this file you are currently reading as the zonefile 
  175. ;    for your reverse domain. Pls remember to make the necessary 
  176. ;    changes:
  177. ;     ie
  178. ;        - replace the references to <your_primary_nameserver> 
  179. ;          and <your_contact_address> with the real data, and 
  180. ;        - edit the PTR records as indicated below..
  181. ;
  182. ;    In it you can register the PTR records for your domain. Pls note 
  183. ;    that you cannot use the traditional
  184. ;        XX.$fc.$fb.$fa.in-addr.arpa.    IN PTR    <somehostname>
  185. ;    notation (giving the full reverse domainname on the LHS), 
  186. ;    since you will have to use the delegated subdomain. We advise 
  187. ;    you to use the pre-listed records below, only giving the last 
  188. ;    octet in the host address. Please do *not* change the \$ORIGIN.
  189. ;
  190. ;    Pls note that you can only list addresses from
  191. ;        $fd to $ld
  192. ;    in this file, and that the first and last addresses in your 
  193. ;    allocated block cannot be used for hosts (they are reserved 
  194. ;    for the network and broadcast address respectively).
  195. ;
  196. ;    We have (or will shortly) set up CNAME translations from the
  197. ;            XX.$fc.$fb.$fa.in-addr.arpa names to the
  198. ;        XX.$subdomain.$fc.$fb.$fa.in-addr.arpa names.
  199. ;
  200. ;    For more information on this allocation scheme, pls see
  201. ;    ftp://ftp.internic.net/internet-drafts/draft-degroot-classless-inaddr-0
  202. 1.txt
  203. ;    
  204. ;    NOTE: pls enter your primary and secondary servers and contact 
  205. ;    address below (don't forget the trailing '.')
  206. ;    >>>     Replace the '\@' in the contact address with '.' !!
  207. ;
  208. ;    CAVEAT ADMINISTRATOR: *never* use '#' as the comment character 
  209. ;    in files used by the nameserver (named.boot, zonefiles, etc). 
  210. ;    The correct comment character is the semicolon (';'). 
  211. ;    named might not work if you use '#' !!!!
  212. ;
  213. ;    IMPORTANT: DO NOT FORGET TO UPDATE THE SERIAL NUMBER 
  214. ;    EACH TIME YOU CHANGE THIS FILE !!!
  215. ;    
  216. \$ORIGIN $subdomain.$fc.$fb.$fa.in-addr.arpa.
  217. \@    IN    SOA    $opt_primary. $opt_contact. (
  218.             $opt_serial
  219.             $opt_refresh
  220.             $opt_retry
  221.             $opt_expire
  222.             $opt_minimum )
  223.     IN    NS    $opt_primary.
  224. EOF
  225. for $i (@opt_secondary) {
  226.     print SUB "\tIN\tNS\t$i.\n";
  227.     }
  228. print SUB <<"EOF";
  229. ;------
  230. ;
  231. ;    note that you cannot use the first 
  232. ;        ($fa.$fb.$fc.$fd = network address)
  233. ;    and last ($la.$lb.$lc.$ld = broadcast) address 
  234. ;    for hosts (PTR).!!
  235. ;
  236. ;    The individual PTR records below are still commented out.
  237. ;    fill in the correct hostnames and remove the leading ';'.
  238. ;    We advise that you only uncomment the PTR record you 
  239. ;    really need.
  240. ;
  241. EOF
  242.  
  243. print INC <<"EOF";
  244. ;
  245. ;    delegation for $ARGV[0]
  246. ;        (addresses from $fa.$fb.$fc.$fd to $la.$lb.$lc.$ld)
  247. ;
  248. ;    this file should be "include'd" in the 
  249. ;        $fc.$fb.$fa.in-addr.arpa zonefile
  250. ;
  251. $subdomain    IN    NS    $opt_primary.
  252. EOF
  253. for $i (@opt_secondary) {
  254.     print INC "\tIN\tNS\t$i.\n";
  255.     }
  256. print INC "\n";
  257.  
  258. for $dd (($fd+1) .. ($ld-1)) {
  259.     print SUB ";$dd    IN    PTR    <some_hostname_$dd>.\n";
  260.     print INC "$dd    IN    CNAME    $dd.$subdomain.$fc.$fb.$fa.in-addr.arpa
  261. .\n";
  262.     }
  263.  
  264. close(SUB);
  265. close(INC);
  266.  
  267. sub unp {
  268.     local($o) = $_[0];
  269.     local($r);
  270.     local($a,$b,$c,$d);
  271.  
  272.     $d = $o & 0x000000ff;
  273.         $o >>= 8;
  274.     $c = $o & 0x000000ff;
  275.         $o >>= 8;
  276.     $b = $o & 0x000000ff;
  277.         $o >>= 8;
  278.     $a = $o & 0x000000ff;
  279.  
  280.     return($a,$b,$c,$d);
  281.     }
  282.  
  283.  
  284.